package initialize

import (
	"github.com/gin-gonic/gin"
	"github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	_ "go-gin-admin/docs"
	"go-gin-admin/global"
	"go-gin-admin/middleware"
	"go-gin-admin/router"
	"net/http"
)

func Routers() *gin.Engine  {
	var Router = gin.Default()
	// 为用户头像和文件提供静态地址
	Router.StaticFS(global.GVA_CONFIG.LocalUpload.AvatarPath,http.Dir(global.GVA_CONFIG.LocalUpload.AvatarPath))
	Router.StaticFS(global.GVA_CONFIG.LocalUpload.FilePath,http.Dir(global.GVA_CONFIG.LocalUpload.FilePath))
	global.GVA_LOG.Debug("使用中间件logger")
	Router.Use(middleware.Cors())
	global.GVA_LOG.Debug("使用跨越中间件")
	Router.GET("/swagger/*any",ginSwagger.WrapHandler(swaggerFiles.Handler))
	global.GVA_LOG.Debug("注册swagger 句柄")
	ApiGroup := Router.Group("")
	router.InitUserRouter(ApiGroup)
	return Router
}
